package photogram

import (
	"public_security/controllers"
	"public_security/models"
	"public_security/models/photogram"
)

// 一线剪影 API
type PhotogramController struct {
	controllers.BaseController
}

func (i *PhotogramController) Prepare() {
	i.BasePrepare()
}

// @Title create
// @Description 创建剪影
// @Param	body		body 	models.Photogram	 true		"请求参数"
// @Success 200 success
// @router /create [post]
func (i *PhotogramController) Create() interface{} {
	art := new(models.Photogram)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = photogram.Create(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "创建成功")
}

// @Title update
// @Description 修改剪影
// @Param	body		body 	models.Photogram	 true		"请求参数"
// @Success 200 success
// @router /update [post]
func (i *PhotogramController) Update() interface{} {
	art := new(models.Photogram)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = photogram.Update(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "修改成功")
}

// @Title remove
// @Description 删除剪影
// @Param	body		body 	models.Photogram	 true		"请求参数"
// @Success 200 success
// @router /remove [post]
func (i *PhotogramController) Remove() interface{} {
	art := new(models.Photogram)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = photogram.Remove(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "删除成功")
}

// @Title query
// @Description 查询剪影
// @Param	body		body 	models.Photogram	 true		"请求参数"
// @Success 200 {object} models.Photogram
// @router /query [post]
func (i *PhotogramController) Query() interface{} {
	art := new(models.Photogram)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	page := art.GetPageInfoNew()
	results, page := photogram.Query(art, page)
	return i.ToMessageSuccess(results, "查询成功", map[string]interface{}{"pageInfo": page})
}
